﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<SDT.Admin.ViewModels.OrderIndexViewModels>" %>
<%@ Import Namespace="SDT.Lib.Helpers" %>
<%@ Import Namespace="SDT.Lib.Paging" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
	Đơn hàng
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="Header" runat="server">
    Danh sách đơn hàng
</asp:Content>
<asp:Content ID="Content6" ContentPlaceHolderID="Message" runat="server">
    <%=ViewData["MessageInfo"]!=null? "<p class='perror'>"+Html.Encode(ViewData["MessageInfo"])+"</p>":string.Empty%>  
</asp:Content>
<asp:Content ID="Content4" ContentPlaceHolderID="Toolbar" runat="server">
     
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <%if(ViewData["MessageInfo"]==null){ %>
	<form action="/Order" method="post" name="adminForm" id="adminForm">
		<table width="100%">
			<tr>
			    <td width="220">
					<%= Html.RadioButton("durationType", "0", Model.InYear > 0 ? false : true, new { id = "duration" })%>Chọn giai đoạn
					<%= Html.RadioButton("durationType", "1",Model.InYear>0? true: false, new { id = "year" })%>Chọn theo năm
				</td>
				<td>
					<div id="select_duration" <%=Model.InYear>0 ? "style=\"display:none\"":"style=\"display:block\"" %>>
						Từ <%= Html.TextBox("fromDate", (Model.FromDate != DateTime.MinValue && Model.FromDate !=null)? Model.FromDate.ToString("dd/MM/yyyy") : "", new { @class = "datepicker", style = "width:80px" })%> đến <%= Html.TextBox("toDate", (Model.ToDate != DateTime.MinValue && Model.ToDate != null) ? Model.ToDate.ToString("dd/MM/yyyy") : "", new { @class = "datepicker", style = "width:80px" })%>
					</div>
					<div id="select_year" <%=Model.InYear>0 ? "style=\"display:block\"":"style=\"display:none\"" %>>
						<select id="inYear" name="inYear">
							<option value="">-- Năm --</option>
							<% foreach (var year in Model.OperationDurations) { %>
							<option value="<%= year.ToString() %>" <%=Model.InYear>0 && Model.InYear==year ? "selected=\"selected\"":"" %>><%= year.ToString() %></option>
							<% } %>
						</select>						
					</div>
				</td>
				<td align="left"><%=Html.TextBox("Keyword", Model.Keyword, new { style = "width:150px" })%><input type="submit" value="Tìm kiếm" /></td>
			    <td align="right">
				    <%=Html.DropDownList("ddlStatus", new SelectList(Model.OrderStatus, "Key", "Value", Model.StatusID).ToList(), "- Trạng thái đơn hàng -", new { onchange = "document.adminForm.submit();", style = "width:80px" })%>
				    <%=Html.DropDownList("ddlPayment", new SelectList(Model.Payments, "ID", "Name", Model.PaymentID).ToList(), "- Phương thức thanh toán-", new { onchange = "document.adminForm.submit();" , style="width:80px"})%>
				    <%=Html.DropDownList("ddlOrderType", new SelectList(Model.OrderTypes, "Key", "Value", Model.TypeID).ToList(), "- Loại đơn hàng -", new { onchange = "document.adminForm.submit();", style = "width:80px" })%>
			    </td>
			</tr>
		</table>
		<script type="text/javascript">
		    $(document).ready(function() {
		        $.datepicker.setDefaults($.datepicker.regional['vi']);
		        $(".datepicker").datepicker({
		            dateFormat: "dd/mm/yy",
		            changeMonth: true,
		            showOn: "button",
		            buttonImage: "/Images/calendar.gif",
		            buttonImageOnly: true,
		            changeYear: true
		        });
		        $(".datepicker").mask("99/99/9999");
		        $("#duration").click(function() {
		            $("#select_duration").show();
		            $("#select_year").hide();
		        });
		        $("#year").click(function() {
		            $("#select_duration").hide();
		            $("#select_year").show();
		        });
		    });		
		</script>
		<table width="100%" class="adminlist">
			<tr>
				<th width="10" align="right">
					STT
				</th>
				<th width="30">&nbsp;</th>
				<th width="30"></th>				
				<th>
					<%= Html.Sort("Tên khách hàng", "CustomerID", ViewData["orderDir"].ToString(), ViewData["order"].ToString())%>
				</th>
				<th>
					<%= Html.Sort("Trạng thái", "Status", ViewData["orderDir"].ToString(), ViewData["order"].ToString())%>
				</th>
				<th>
					<%= Html.Sort("Ngày đặt hàng", "AddDate", ViewData["orderDir"].ToString(), ViewData["order"].ToString())%>
				</th>
				<th>
					<%= Html.Sort("Ngày giao hàng", "DeliveryDate", ViewData["orderDir"].ToString(), ViewData["order"].ToString())%>
				</th>
				<th>
					Tổng tiền
				</th>
				<th>
					<%= Html.Sort("Mã bưu điện", "EmsCode", ViewData["orderDir"].ToString(), ViewData["order"].ToString())%>
				</th>
				<th>
					<%= Html.Sort("Phiếu giảm giá", "Coupon", ViewData["orderDir"].ToString(), ViewData["order"].ToString())%>
				</th>
				<th>
					<%= Html.Sort("ID", "ID", ViewData["orderDir"].ToString(), ViewData["order"].ToString())%>
				</th>
			</tr>
		<% 
			int i = Model.Orders.PageIndex*Model.Orders.PageSize;
    		foreach (var item in Model.Orders) {
				i++;
		%>		
			<tr>
				<td align="right" style="width: 30px">
					<%= i.ToString() %>
				</td>
				<td align="center" style="width: 30px">
					<%= Html.ActionImage("Sửa", "icon-24-edit.png", "Order", "Edit", new Dictionary<string, object>() { { "id", item.ID } })%>
				</td>
				 <td align="center" style="width: 26px">
					<%= Html.ActionImage("Xóa", "icon-24-delete.png", "Order", "Delete", new Dictionary<string, object>() { { "id", item.ID } })%>
				</td>
				<td>
					<%= Html.ActionLink(item.ReFullName, "Details", new { id = item.ID })%>
				</td>				
				<td >
					<%= Html.Encode(item.Status>0? Model.OrderStatus[item.Status]:string.Empty)%>
				</td>
				<td>
					<%= Html.Encode(string.Format("{0:dd/MM/yyyy}", item.AddDate)) %>
				</td>
				<td>
					<%= Html.Encode(string.Format("{0:dd/MM/yyyy}", item.DeliveryDate))%>
				</td>
				<td >
					<%var total =item.TotalValue.HasValue? item.TotalValue.Value: item.OrderDetails.Sum(e => e.Price * e.Quantity); %>
                     <%=string.Format("{0:0,0.0}",total) %>                       
				</td>
				<td><%=Html.Encode(item.EmsCode) %></td>
				<td><%=Html.Encode(item.Coupon) %></td>
				<td style="width: 30px">
					<%= Html.Encode(item.ID) %>
				</td>
			</tr>
	    
		<% } %>

		</table>
		<%= Html.Hidden("order")%>
		<%= Html.Hidden("orderDir")%>
		<table width="100%">
            <tr>
                <td align="center">
             
                <div class="pager">
                <label>Hiển thị #</label>
                    <%
                        int[] pageSizeList = {1, 5, 10, 15, 20, 25, 50, 100};
                    %>
                    <%= Html.DropDownList("PageSize", new SelectList(pageSizeList, Model.Orders.PageSize), new { onchange = "document.adminForm.submit();" })%>

                    <%= Html.Pager(Model.Orders.PageSize, Model.Orders.PageNumber, Model.Orders.TotalItemCount)%>
                    </div>
                </td>
            </tr>
        </table>
	</form>
 <% } %>
</asp:Content>
